package com.hongyuan.sellfitness.ui.person.activity;

import android.os.Bundle;
import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityCouponHubBinding;
import com.hongyuan.sellfitness.ui.person.view_mode.CouponHubModel;
import com.hongyuan.sellfitness.ui.person.viewpage_adapter.CouponHubViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.BR;

public class CouponHubActivity extends CustomActivity<ActivityCouponHubBinding, CouponHubModel> {

    CouponHubViewPagerAdapter pagerAdapter;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_coupon_hub;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public CouponHubModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CouponHubModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        pagerAdapter = new CouponHubViewPagerAdapter(getSupportFragmentManager());

        binding.mViewPager.setAdapter(pagerAdapter);
        binding.tab.setupWithViewPager(binding.mViewPager);

        binding.comBack.setOnClickListener(view -> finish());

    }

    @Override
    public void initData() {
        super.initData();

        viewModel.requestData(Constants.COUPON_FOR_LIST);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();


        viewModel.uc.setHead.observe(this, couponHubTops -> {
            pagerAdapter.setData(couponHubTops);
            binding.mViewPager.setOffscreenPageLimit(couponHubTops.size());
        });
    }
}
